package au.edu.utas.yu_qiao_group.luckyman;

import android.app.Activity;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;

import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.bottomnavigation.LabelVisibilityMode;

import androidx.appcompat.app.AppCompatActivity;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;
import au.edu.utas.yu_qiao_group.luckyman.db.Database;

import static au.edu.utas.yu_qiao_group.luckyman.R.id.nav_host_fragment;

public class MainActivity extends AppCompatActivity {
  public SQLiteDatabase mDb;

  public static final String KEY_DATA_PRIVATE = "data_private";
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    initNavigationBottomBar();
    connectDB();
    initSharedPreferences();
  }

  protected void initNavigationBottomBar() {
    BottomNavigationView navView = findViewById(R.id.nav_view);
    AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(R.id.nav_raffles_home, R.id.nav_drawing, R.id.nav_record_list, R.id.nav_account)
            .build();
    navView.setLabelVisibilityMode(LabelVisibilityMode.LABEL_VISIBILITY_LABELED); // we fixed text invisible problem by reading source code 'isShifting' method of BottomNavigationMenuView;
    NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
    NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
    NavigationUI.setupWithNavController(navView, navController);
  }

  protected void connectDB() {
    Database databaseConnection = new Database(this);
    mDb = databaseConnection.open();
  }

  protected void initSharedPreferences() {
    SharedPreferences mSharedPreferences = getSharedPreferences(KEY_DATA_PRIVATE, Activity.MODE_PRIVATE);
    SharedPreferences.Editor editor = mSharedPreferences.edit();
    editor.putString("login_user_name", "default user");
    editor.putString("login_user_company", "DEFAULT Company Ltd.");
    editor.putString("login_user_company_id", "012345677");
    editor.putString("login_user_company_contact", "yqiao1@utas.edu.au");
    editor.putString("login_user_company_info", "International Lottery company founded in China since 1990...");
    editor.commit();
  }
}
